package ifosup.matthias.runnable;


public class MyRunnable implements Runnable
{
	int n=0;
	static Object lock = new Object();
	public void run() 
	{
		while(true)
		{
			synchronized(lock){
			increment();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			decrement();
			System.out.println("MyThread"+" "+n+" "+Thread.currentThread());
			}
		}
	}
	
	public synchronized void increment()
	{
		n+=1;
	}

	public synchronized void decrement()
	{
		n-=1;
	}

}
